home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!marnold
- From: marnold@netcom.com (Matt Arnold)
- Subject: Re: The STL and nested structures
- Message-ID: <marnoldDpn0HH.3z2@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- References: <4ju9q7$fa1$1@mhadg.production.compuserve.com> <316a26d7.2989288@news.cyberport.com>
- Date: Wed, 10 Apr 1996 08:20:04 GMT
- Sender: marnold@netcom23.netcom.com
-
- tangent@cyberport.com (Warren Young) writes:
-
- >Alan Huff <74312.2300@CompuServe.COM> wrote:
-
- >>I am having a problem using the STL with structures defined within
- >>a class definition. Consider the following code fragment.
- >>
- >>>#include <vector.h>
- >>>class Bar {
- >>> struct Foo {
- >>> int value;
- >>> };
- >>>
- >>> vector< Foo > fooContainer;
- >>>}
- >>
- >>The compiler I am using (VC 4.1) refuses to compile. An error is
- >>generated the says "'Foo' : undeclared identifier" at line 75 in
- >>vector.h.
-
- >It _is_ undeclared, just as a variable local to a function foo() is
- >undeclared in a function bar(). What you want to say is:
-
- >vector<Bar::Foo> fooContainer;
-
- This should not be necessary. Nested class Foo should be visible for
- use in template member Bar::fooContainer. fooContainer is in Bar's
- scope. There should be no problem referring to it within Bar.
-
- I think Visual C++ is broken on the above code. It compiles fine in
- Borland C++.
-
- Your above function scope anology doesn't apply here. Foo is already
- being used in the correct scope.
-
- >Even this won't work until Foo is placed in the public section of the
- >class (as shown above, it's in the private (default) section).
-
- That requirement would make private nested implementation class'
- impossible, wouldn't it?
-
- STL, for example, uses this exact construct. Nested structs and
- classes in private and protected sections of the nesting class that
- are passed on---unqualified---as parameters to templated members of
- the nesting class (see the rb_tree_node nested struct in the rb_tree
- class, found in "tree.h").
-
- Is it true that STL is currently incorrectly implemented?
-
- Regards,
- -------------------------------------------------------------------------
- Matt Arnold | | ||| | |||| | | | || ||
- marnold@netcom.com | | ||| | |||| | | | || ||
- Boston, MA | 0 | ||| | |||| | | | || ||
- 617.389.7384 (h) 617.576.2760 (w) | | ||| | |||| | | | || ||
- C++, MIDI, Win32/95 developer | | ||| 4 3 1 0 8 3 || ||
- -------------------------------------------------------------------------
-
-